package app;

import app.quiz.util.HTMLWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created with IntelliJ IDEA.
 * User: Georgiana.Scarlat
 * Date: 8/8/12
 * Time: 3:11 PM
 */
public class HelloServlet extends HttpServlet {

    private String pageTitle, welcomeMessage;

    @Override
    public void init() throws ServletException {
        super.init();
        pageTitle = "First WebPage\n";
        welcomeMessage = "Welcome to my first Web Page!\n";
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws javax.servlet.ServletException, IOException {

        response.setContentType("text/html");
        PrintWriter printWriter = response.getWriter();
        HTMLWriter head = new HTMLWriter(pageTitle), body = new HTMLWriter(welcomeMessage), page;
        head.newLine().bold().italic().htmlHead();
        body.italic().newParagraph().htmlBody();
        page = new HTMLWriter(head.toString() + body.toString());

        printWriter.print(page.htmlPage());


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws javax.servlet.ServletException, IOException {

        doPost(request, response);
    }

}
